﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Jn698._45GWTool.Controls
{
    /// <summary>
    /// DataGridEx.xaml 的交互逻辑
    /// </summary>
    public partial class DataGridEx : DataGrid
    {
        public DataGridEx()
        {
            InitializeComponent();
        }
        public DataGrid DynamicBindHeadersCols
        {
            get { return (DataGrid)GetValue(DynamicBindHeadersColsProperty); }
            set { SetValue(DynamicBindHeadersColsProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DynamicBindHeadersCols.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DynamicBindHeadersColsProperty =
            DependencyProperty.Register("DynamicBindHeadersCols", typeof(DataGrid), typeof(DataGridEx), new PropertyMetadata((s, e) =>
            {
                var dp = s as DataGrid;
                foreach (var item in (e.NewValue as DataGrid).Columns)
                {
                    dp.Columns.Add(new DataGridTextColumn()
                    {
                        Header = item.Header,
                        Binding = item.ClipboardContentBinding,
                        Width = item.Width,
                        Visibility = item.Visibility,
                        IsReadOnly = item.IsReadOnly,
                    });
                }
            }));

    }
}
